
version 15

clear
set more off

cd "TO COMPLETE"

use "Cleaned data\turnout.dta", clear

set more off 
set scheme tfl

************ summary statistics

sutex EM_1 MLP_1 JLM_1 FF_1 BH_1 if year ==2017 & tour ==1 & time ==20, minmax
sutex EM_2 MLP_2  if year ==2017 & tour ==2 & time ==20 , minmax
sutex turnout if year ==2017 & tour ==1 & time ==20, minmax
sutex turnout if year ==2017 & tour ==2 & time ==20, minmax
sutex raining tempmax if year ==2017 & tour ==1 & time ==20, minmax
sutex raining tempmax if year ==2017 & tour ==2 & time ==20, minmax

***** Table 1 ****
eststo: reg turnout i.time##i.tour if year==2017 [pweight=weight_both], cluster(code_dep) 
eststo: reg turnout i.time##i.tour if year==2017 , cluster(code_dep) 
eststo: reg turnout i.time##i.tour time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)
eststo: reg turnout i.time##i.tour if never_rain ==1 & year==2017 [pweight=weight_both], cluster(code_dep)

esttab using "Output/table1.tex", label replace ///
	star(* 0.10 ** 0.05 *** 0.01) noomit nonotes nobase interaction(" X ")  drop(*tempmax* *raining*) p 
eststo clear

******* Figure 1 ***************
label define tour2 1 "Round 1" 2 "Round 2"
label values tour tour2

eststo: reg turnout i.time##i.tour if year==2022 [pweight=weight_both], cluster(code_dep) 
margins, at (time = (12 17 20) tour = ( 1 2))
marginsplot, graphregion(fcolor(white)) xtitle("") title("") ytitle("Turnout (%)")  ///
 xline(16, lpattern(dash) lcolor(gs12)) xscale(range(11 21)) yscale(range(25 85)) ylabel(30 (10) 80) /// 
 		plot1opts(msymbol(Sh) lcolor(black) mcolor(black))  /// marker for first line
		plot2opts(msymbol(Oh) lcolor(gs6)  mcolor(gs6)) /// marker for second line
		ci1opts(color(black)) ci2opts(color(gs6))
graph export "Output/elections2022.png", replace width(550) height(600)

eststo: reg turnout i.time##i.tour if year==2017 [pweight=weight_both], cluster(code_dep) 
margins, at (time = (12 17 20) tour = ( 1 2))
marginsplot, graphregion(fcolor(white)) xtitle("") title("") ytitle("Turnout (%)")  ///
 xline(16, lpattern(dash) lcolor(gs12)) xscale(range(11 21)) yscale(range(25 85)) ylabel(30 (10) 80) /// 
 		plot1opts(msymbol(Sh) lcolor(black) mcolor(black))  /// marker for first line
		plot2opts(msymbol(Oh) lcolor(gs6)  mcolor(gs6)) /// marker for second line
		ci1opts(color(black)) ci2opts(color(gs6))
graph export "Output/elections2017.png", replace width(550) height(600)

eststo: reg turnout i.time##i.tour if year==2012 [pweight=weight_both], cluster(code_dep) 

margins, at (time = (12 17 20) tour = ( 1 2))
marginsplot, graphregion(fcolor(white)) xtitle("") title("") ytitle("Turnout (%)")  ///
 xline(16, lpattern(dash) lcolor(gs12))  xscale(range(11 21))  yscale(range(25 85)) ylabel(30 (10) 80) /// 
 		plot1opts(msymbol(Sh) lcolor(black) mcolor(black))  /// marker for first line
		plot2opts(msymbol(Oh) lcolor(gs6)  mcolor(gs6)) /// marker for second line
		ci1opts(color(black)) ci2opts(color(gs6))
graph export "Output/elections2012.png", replace width(550) height(600)

label values tour tour

eststo clear
************* Table 2 ********************
*** Diff-in-diff-in-diff with 2022
eststo: reg turnout i.time##i.tour##ib2022.year if year==2022 | year==2017 [pweight=weight_both], cluster(code_dep)
*** Diff-in-diff-in-diff with 2012
eststo: reg turnout i.time##i.tour##i.year if year==2012 | year==2017 [pweight=weight_both], cluster(code_dep)

esttab using "Output/table2.tex", label replace ///
	star(* 0.10 ** 0.05 *** 0.01) noomit nonotes nobase interaction(" X ")  mtitles("Comparison 2022" "Comparison 2012"  "Comparison 2007") p
eststo clear 
***

**** Table 3: Diff-in-Diff with being close to the two borders ****

eststo: reg turnout i.time##i.tour##veryclosebe time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)
eststo: reg turnout i.time##i.tour##closebe time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)
eststo: reg turnout i.time##i.tour##veryclosech time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)
eststo: reg turnout i.time##i.tour##closech time##raining time##c.tempmax_std if year==2017 [pweight =weight_both], cluster(code_dep)

esttab using "Output/table3.tex", label replace ///
	p star(* 0.10 ** 0.05 *** 0.01) noomit nonotes nobase compress interaction(" X ") fonttbl(\f0\fnil Arial; ) nogaps   drop(*tempmax* *raining*)
eststo clear


**** Table 4: Diff-in-Diff with political preferences ****

eststo: reg turnout i.time##i.tour##em_first time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)
eststo: reg turnout i.time##i.tour##mlp_first time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)
eststo: reg turnout i.time##i.tour##left_deps time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)
eststo: reg turnout i.time##i.tour##right_deps time##raining time##c.tempmax_std if year==2017 [pweight=weight_both], cluster(code_dep)

esttab using "Output/table4.tex", label replace ///
	star(* 0.10 ** 0.05 *** 0.01) noomit nonotes nobase compress interaction(" X ") nogaps p  drop(*tempmax* *raining*) ///
	mtitles("" "" "" "") 
eststo clear

